home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / TRAVERSA.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  9.8 KB  |  313 lines

  1. /*
  2.  * $Id: traversal_test.java,v 1.12 1996/10/03 19:46:51 hudson Exp $
  3.  * $Author: hudson $
  4.  */
  5.  
  6. package sub_arctic.test;
  7.  
  8. import sub_arctic.lib.interactor;
  9. import sub_arctic.lib.interactor_applet;
  10. import sub_arctic.lib.manager;
  11. import sub_arctic.lib.interactor_consts;
  12. import sub_arctic.lib.top_level;
  13. import sub_arctic.lib.base_parent_interactor;
  14. import sub_arctic.lib.button;
  15. import sub_arctic.lib.drag_icon;
  16. import sub_arctic.lib.std;
  17. import sub_arctic.lib.backdrop;
  18. import sub_arctic.lib.line_display;
  19. import sub_arctic.lib.row;
  20. import sub_arctic.lib.text_toggle_collection;
  21. import sub_arctic.lib.toggle;
  22. import sub_arctic.lib.icon;
  23. import sub_arctic.lib.interactor_pred;
  24. import sub_arctic.lib.traversal_xform;
  25. import sub_arctic.input.std_drag_filters;
  26. import sub_arctic.input.event;
  27. import sub_arctic.input.callback_object;
  28. import sub_arctic.input.pressable;
  29. import sub_arctic.input.move_draggable;
  30. import sub_arctic.input.pick_collector;
  31. import sub_arctic.output.style;
  32. import sub_arctic.output.style_manager;
  33. import sub_arctic.output.loaded_image;
  34. import sub_arctic.lib.sub_arctic_error;
  35.  
  36. import java.awt.Point;
  37. import java.awt.Rectangle;
  38.  
  39. public class traversal_test extends interactor_applet 
  40. implements interactor_consts, callback_object {
  41.  
  42.   public static int setting = 0;
  43.  
  44.   /**
  45.    * Shorthand for generating a button's image in the default style.
  46.    */
  47.   public static loaded_image[] std_label(String s) {
  48.     style st=style_manager.current_style();
  49.     return st.button_make_images(s,style_manager.default_font(),10,5,false);
  50.   }
  51.  
  52.   public void callback(interactor from_obj, event evt, int cb_n, Object info)
  53.     {
  54.       int i = ((Integer)from_obj.user_info()).intValue();
  55.       System.out.println("setting = " + (i-1));
  56.       setting = i-1;
  57.     }
  58.  
  59.   public void build_ui(base_parent_interactor top) 
  60.     {
  61.       row       r;
  62.       String    labels[] = {
  63.     "\"Grab\" point", "Top-left", "Top-right", "Bottom-left", 
  64.     "Bottom-right", "Center"};
  65.  
  66.       /*** MOST OF THIS WE JUST STOLE FROM ANOTHER TEST... ***/
  67.  
  68.       r = new row(5, 5, true, false, row.CENTER_JUSTIFIED);
  69.       top.add_child(r);
  70.       r.add_child(new text_toggle_collection(labels, true, -1, this));
  71.       ((toggle)(r.child(0).child(1))).set_cur_state(1);
  72.  
  73.       base_parent_interactor p1 = new base_parent_interactor(10,10,380,380);
  74.       r.add_child(p1);
  75.       p1.add_child(new backdrop(400,400,std.stipple25()));
  76.  
  77.       loaded_image[] lab1 = std_label("Traversal Test");
  78.       xdrag_icon_t1 drag = new xdrag_icon_t1(10,10,lab1[0]);
  79.       p1.add_child(drag);
  80.  
  81.       lab1 = std_label("Interactor Tree dumped to System.out");
  82.       xdrag_icon_t2 drag2 = new xdrag_icon_t2(60,60,lab1[0]);
  83.       p1.add_child(drag2);
  84.  
  85.       line_display ln = new line_display(50,50,250,50,0);
  86.       p1.add_child(ln);
  87.       ln = new line_display(50,50,50,150,0);
  88.       p1.add_child(ln);
  89.       ln = new line_display(250,50,250,150,0);
  90.       p1.add_child(ln);
  91.       ln = new line_display(50,150,250,150,0);
  92.       p1.add_child(ln);
  93.  
  94.       ln = new line_display(0,p1.h()-20,p1.w()-10,p1.h()-20,0);
  95.       p1.add_child(ln);
  96.  
  97.       ln = new line_display(p1.w()-10,0,p1.w()-10,p1.h()-20,0);
  98.       p1.add_child(ln);
  99.  
  100.       ln = new line_display(10,300,350,20,0);
  101.       p1.add_child(ln);
  102.  
  103.       lab1 = std_label("Traversal Test");
  104.       xdrag_icon_t3 drag3 = new xdrag_icon_t3(10,300,lab1[0]);
  105.       p1.add_child(drag3);
  106.  
  107.       lab1 = std_label("Traversal Test");
  108.       xdrag_icon_t4 drag4 = new xdrag_icon_t4(200,10,lab1[0]);
  109.       p1.add_child(drag4);
  110.  
  111.       /*** HERE IS THE ACTUAL TEST... ***/
  112.  
  113.       System.out.println("-----------------------------------------");
  114.       System.out.println("Doing post-order traversal of entire tree");
  115.       System.out.println("-----------------------------------------");
  116.       pick_collector result = new pick_collector();
  117.       top.traverse_and_collect(0, TRAV_POST, null, null, null, null, result);
  118.       for (int i = 0; i < result.num_picks(); i++)
  119.     System.out.println("-->" + result.pick(i).obj.tag_str());
  120.  
  121.       System.out.println("------------------------");
  122.       System.out.println("Doing drawing order dump");
  123.       System.out.println("------------------------");
  124.       result.reset();
  125.       interactor_pred print = new print_pred();
  126.       traversal_xform incr_int = new incr_int_xform();
  127.       top.traverse_and_collect(1, TRAV_DRAW, print, null, incr_int, 
  128.                    new Integer(0), result);
  129.  
  130.       System.out.println("---------------------");
  131.       System.out.println("Doing pick order dump");
  132.       System.out.println("---------------------");
  133.       result.reset();
  134.       top.traverse_and_collect(1, TRAV_PICK, print, null, incr_int, 
  135.                    new Integer(0), result);
  136.  
  137.       System.out.println("-----------------------------------------");
  138.       System.out.println(
  139.              "Doing drawing order dump pruning under text_toggle_collection");
  140.       System.out.println("-----------------------------------------");
  141.       result.reset();
  142.       interactor_pred stop_at_ttc = new not_ttc_pred();
  143.       top.traverse_and_collect(1, TRAV_DRAW, print, stop_at_ttc, incr_int, 
  144.                    new Integer(0), result);
  145.     }
  146. }
  147.  
  148. class print_pred implements interactor_pred {
  149.   public boolean test(interactor obj, Object parameters) 
  150.     {
  151.       if (!(parameters instanceof Integer)) 
  152.     throw new sub_arctic_error("Non integer parameter");
  153.       int indent = ((Integer)parameters).intValue();
  154.       for (int i=0; i<indent; i++)
  155.     System.out.print("   ");
  156.       System.out.println(obj.getClass().getName() + " " + obj.hashCode());
  157.       return false;
  158.     }
  159. }
  160.  
  161. class incr_int_xform implements traversal_xform {
  162.   public Object xform(
  163.     Object     parent_parameters, 
  164.     interactor child_obj, 
  165.     int        child_index) 
  166.     {
  167.       if (!(parent_parameters instanceof Integer)) 
  168.     throw new sub_arctic_error("Non integer parameter");
  169.       return new Integer(((Integer)parent_parameters).intValue() + 1);
  170.     }
  171. }
  172.  
  173. class not_ttc_pred implements interactor_pred {
  174.   public boolean test(interactor obj, Object parameters) 
  175.     {
  176.       return !(obj instanceof text_toggle_collection);
  177.     }
  178. }
  179.  
  180. class xdrag_icon_t1 extends icon implements pressable, move_draggable {
  181.   public xdrag_icon_t1(int x, int y, loaded_image img) 
  182.     {super(x,y,img);}
  183.   public int drag_feature_point()
  184.     {
  185.       return drag_limit_test.setting;
  186.     }
  187.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  188.     {
  189.       return std_drag_filters.limit_to_parent(orig_pt,this,true,10,20, f_pt);
  190.     }
  191.   public boolean press(event evt, Object user_info)
  192.     {
  193.       manager.move_drag_focus.set_focus_to(this, evt, user_info);
  194.       return true;
  195.     }
  196.   public boolean release(event evt, Object user_info)
  197.     {
  198.       return true;
  199.     }
  200.   public boolean drag_start(
  201.     event evt, int xv, int yv, int gx, int gy, Object user_info)
  202.     { return true; }
  203.   public boolean drag_feedback(
  204.     event evt,
  205.     int x_pos, int y_pos,
  206.     int start_x, int start_y,
  207.     int grab_x, int grab_y,
  208.     Object user_info)
  209.     {
  210.  
  211.       /* move our position */
  212.       set_pos(x_pos, y_pos);
  213.       return true;
  214.     }
  215.   public boolean drag_end(
  216.     event evt,
  217.     int x_pos, int y_pos,
  218.     int start_x, int start_y,
  219.     int grab_x, int grab_y,
  220.     Object user_info)
  221.     {
  222.       /* let drag_feedack to all the work */
  223.       return drag_feedback(evt, x_pos, y_pos, start_x, start_y, grab_x, grab_y,
  224.                                     user_info);
  225.     }
  226. }
  227.  
  228. class xdrag_icon_t2 extends xdrag_icon_t1 {
  229.   public xdrag_icon_t2(int x, int y, loaded_image img) 
  230.     {super(x,y,img);}
  231.   public static Rectangle r = new Rectangle(50,50, 200,100);
  232.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  233.     {
  234.       return std_drag_filters.limit_to_rect(orig_pt,r);
  235.     }
  236. }
  237.  
  238. class xdrag_icon_t3 extends xdrag_icon_t1 {
  239.   public xdrag_icon_t3(int x, int y, loaded_image img) 
  240.     {super(x,y,img);}
  241.   public Point filter_pt(Point orig_pt, interactor drag_obj, Point f_pt)
  242.     {
  243.       return std_drag_filters.limit_to_line_seg(orig_pt, 10, 300, 350,20);
  244.     }
  245. }
  246.  
  247. class xdrag_icon_t4 extends xdrag_icon_t1 {
  248.  
  249.   public xdrag_icon_t4(int x, int y, loaded_image img) 
  250.     {super(x,y,img);}
  251.  
  252.   public boolean drag_start(
  253.     event evt, 
  254.     int x, int y, 
  255.     int grab_x, int grab_y, 
  256.     Object user_info)
  257.     {
  258.       System.out.println("drag_start(evt, " +
  259.     "x="+ x + "," + "y=" + y + "," +
  260.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  261.     "user_info");
  262.       return super.drag_start(evt,x,y,grab_x,grab_y,user_info);
  263.     }
  264.  
  265.   public boolean drag_feedback(
  266.     event evt,     
  267.     int x, int y, 
  268.     int start_x, int start_y, 
  269.     int grab_x, int grab_y, 
  270.     Object user_info)
  271.     {
  272.       System.out.println("drag_feedback(evt, " +
  273.     "x="+ x + "," + "y=" + y + "," +
  274.     "start_x="+ start_x + "," + "start_y=" + start_y + "," +
  275.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  276.     "user_info");
  277.       return 
  278.       super.drag_feedback(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
  279.     }
  280.  
  281.   public boolean drag_end(
  282.     event evt,     
  283.     int x, int y, 
  284.     int start_x, int start_y, 
  285.     int grab_x, int grab_y, 
  286.     Object user_info)
  287.     {
  288.       System.out.println("drag_end(evt, " +
  289.     "x="+ x + "," + "y=" + y + "," +
  290.     "start_x="+ start_x + "," + "start_y=" + start_y + "," +
  291.     "grab_x="+ grab_x + "," + "grab_y=" + grab_y + "," +
  292.     "user_info");
  293.       return super.drag_end(evt,x,y,start_x,start_y,grab_x,grab_y,user_info);
  294.     }
  295. }
  296.  
  297. /*=========================== COPYRIGHT NOTICE ===========================
  298.  
  299. This file is part of the subArctic user interface toolkit.
  300.  
  301. Copyright (c) 1996 Scott Hudson and Ian Smith
  302. All rights reserved.
  303.  
  304. The subArctic system is freely available for most uses under the terms
  305. and conditions described in 
  306.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  307. and appearing in full in the lib/interactor.java source file.
  308.  
  309. The current release and additional information about this software can be 
  310. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  311.  
  312. ========================================================================*/
  313.